import { View } from "../../../mvc/core/View";
import { FlowerBg } from "../common/FlowerBg";
import { TilePanel } from "../equipment/TilePanel";
import { DramaLotteryRender } from "./DramaLotteryRender";
import { ScrollBarDirection } from "../../../../fl/controls/ScrollBarDirection";
import { ScrollPolicy } from "../../../../fl/controls/ScrollPolicy";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { Language } from "../../../../extend/language/Language";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { MoneyUtil } from "../common/util/MoneyUtil";
import { Cache } from "../../cache/Cache";
import { DramaLotteryProfilePanel } from "./DramaLotteryProfilePanel";
import { DramaLotteryOverviewPanel } from "./DramaLotteryOverviewPanel";
import { PulseSharedObject } from "../player/PulseSharedObject";
import { Alert } from "../../../../com/mui/controls/Alert";
import { CheckBoxWin } from "../common/alertwins/CheckBoxWin";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GameConst } from "../../../component/gconst/GameConst";
import { MsgManager } from "../../manager/MsgManager";
import { ELotteryCategory } from "../../../../Message/Public/ELotteryCategory";
import { SPublicNotice } from "../../../../Message/Public/SPublicNotice";
import { SDramaLotteryInfo } from "../../../../Message/Game/SDramaLotteryInfo";
import { SDramaLotteryItemInfo } from "../../../../Message/Game/SDramaLotteryItemInfo";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { ExplorerRumorData } from "../treasure/ExplorerRumorData";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GCheckBox } from "../../../../com/mui/controls/GCheckBox";
type int = number;
//class DramaLotteryMainPanel
    
    export  class DramaLotteryMainPanel extends View
    {
        constructor()
        {
            super();
            this._itemArr = [];
            this.initView();
            return;
        }

        /* internal  */initView(): void
        {
            var loc3=null;
            var loc4=null;
            this._spLeft = new FlowerBg(445, 445);
            this.addChild(this._spLeft);
            this._showList = new TilePanel();
            this._showList.setSize(437, 340);
            this._showList.columnWidth = 210;
            this._showList.rowHeight = 114;
            this._showList.setStyle("cellRenderer", DramaLotteryRender);
            this._showList.direction = ScrollBarDirection.VERTICAL;
            this._showList.scrollPolicy = ScrollPolicy.OFF;
            this._showList.move(14, 16);
            this.addChild(this._showList);
            this._refreshBtn = ObjCreate.createGButton("", 150, 372, 120, 30, this, "ButtonSpecial");
            this._refreshBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onRefreshBtnClick);
            this._costTips = ObjCreate.createTextField("", 285, 365, 120, 20, this);
            this._costTips.autoSize = flash.text.TextFormatAlign.CENTER;
            var loc1=GlobalClass.getBitmap(ImagesConst.Fire);
            loc1.x = 120;
            loc1.y = 407;
            this.addChild(loc1);
            var loc2=ObjCreate.createTextField(Language.getString(70656), 143, 412, 150, 20, this, GlobalStyle.textFormat5);
            loc3 = GlobalClass.getBitmap("Yuanbao");
            loc3.x = 20;
            loc3.y = 373;
            this.addChild(loc3);
            (loc4 = GlobalClass.getBitmap("Yuanbao_bind")).x = 20;
            loc4.y = 395;
            this.addChild(loc4);
            this._ybTx = ObjCreate.createTextField("", 52, 373, 78, 20, this);
            this._ybBindTx = ObjCreate.createTextField("", 52, 395, 78, 20, this);
            this._ybTx.htmlText = MoneyUtil.getGoldHtml(Cache.instance.role.money.gold);
            this._ybBindTx.htmlText = MoneyUtil.getGoldHtml(Cache.instance.role.money.goldBind);
            this._useBindYbCB = ObjCreate.createCheckBox(Language.getString(70657), 284, 388, 140, 20, this);
            ObjCreate.createBg(447, 0, 195, 445, this);
            this._profilePanel = new DramaLotteryProfilePanel();
            this._profilePanel.x = 445;
            this._profilePanel.y = 0;
            addChild(this._profilePanel);
            this._overviewPanel = new DramaLotteryOverviewPanel();
            this._overviewPanel.x = 445;
            this._overviewPanel.y = 200;
            addChild(this._overviewPanel);
            return;
        }

        protected onRefreshBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=false;
            if (this.checkCategory()) 
            {
                loc1 = !PulseSharedObject.isTodayNotTips("DramaLotteryCategoryCheck");
                if (loc1) 
                {
                    Alert.alertWinRenderer = CheckBoxWin;
                    Alert.show(Language.getString(70687), null, Alert.OK | Alert.CANCEL, null, this.onBtnClickHandler);
                }
                else 
                {
                    this.goRefresh();
                }
            }
            else 
            {
                this.goRefresh();
            }
            return;
        }

        /* internal  */goRefresh(): void
        {
            var loc1=0;
            var loc2=false;
            if (this._leftFreeTimes > 0) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.DramaLotteryGoRefreshItem, this._useBindYbCB.selected));
            }
            else 
            {
                loc1 = Cache.instance.role.money.gold + Cache.instance.role.money.goldBind;
                if (loc1 < GameConst.DramaLotteryRefresh) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(70658));
                    return;
                }
                loc2 = !PulseSharedObject.isTodayNotTips("DramaLotteryShopRefresh");
                if (loc2) 
                {
                    Alert.alertWinRenderer = CheckBoxWin;
                    Alert.show(Language.getStringByParam(70674, GameConst.DramaLotteryRefresh), null, Alert.OK | Alert.CANCEL, null, this.onBtnClickHandlerI);
                }
                else 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.DramaLotteryGoRefreshItem, this._useBindYbCB.selected));
                }
            }
            return;
        }

        /* internal  */onBtnClickHandler(arg1: int, arg2: Boolean): void
        {
            if (arg1 == Alert.OK) 
            {
                Alert.resetToDefault();
                this.goRefresh();
            }
            if (arg2) 
            {
                PulseSharedObject.save("DramaLotteryCategoryCheck", true);
            }
            return;
        }

        /* internal  */onBtnClickHandlerI(arg1: int, arg2: Boolean): void
        {
            if (arg1 == Alert.OK) 
            {
                Alert.resetToDefault();
                Dispatcher.dispatchEvent(new DataEvent(EventName.DramaLotteryGoRefreshItem, this._useBindYbCB.selected));
            }
            if (arg2) 
            {
                PulseSharedObject.save("DramaLotteryShopRefresh", true);
            }
            return;
        }

        /* internal  */checkCategory(): Boolean
        {
            var loc1=null;
            var loc2=0;
            if (this._itemArr.length > 0) 
            {
                loc2 = 0;
                while (loc2 < this._itemArr.length) 
                {
                    loc1 = this._itemArr[loc2] as Object;
                    if (loc1.category == ELotteryCategory._ELotteryFress || loc1.category == ELotteryCategory._ELotteryActive) 
                    {
                        return true;
                    }
                    ++loc2;
                }
                return false;
            }
            return false;
        }

        public updateAllBuyHistroy(arg1: SPublicNotice): void
        {
            return;
        }

        public updateInfo(arg1: SDramaLotteryInfo): void
        {
            var loc1=null;
            this._leftFreeTimes = arg1.leftFreeTimes;
            this._itemArr = [];
            var loc2=0;
            while (loc2 < GameConst.DramaLotteryRefreshEx) 
            {
                loc1 = arg1.lotteryItems[loc2] as SDramaLotteryItemInfo;
                this._itemObject = {};
                this._itemObject.index = loc2;
                this._itemObject.itemCode = loc1.itemCode;
                this._itemObject.oldPrice = loc1.oldPrice;
                this._itemObject.newPrice = loc1.newPrice;
                this._itemObject.category = loc1.category;
                this._itemArr.push(this._itemObject);
                ++loc2;
            }
            this._showList.dataProvider = new DataProvider(this._itemArr);
            if (this._leftFreeTimes > 0) 
            {
                this._refreshBtn.label = Language.getStringByParam(70654, this._leftFreeTimes);
                this._refreshBtn.drawNow();
                this._costTips.text = Language.getString(70659);
            }
            else 
            {
                this._refreshBtn.label = Language.getString(70670);
                this._refreshBtn.drawNow();
                this._costTips.text = Language.getString(70655);
            }
            if (this._profilePanel) 
            {
                this._profilePanel.update(arg1.myHistory);
            }
            return;
        }

        public updateMoney(): void
        {
            this._ybTx.htmlText = MoneyUtil.getGoldHtml(Cache.instance.role.money.gold);
            this._ybBindTx.htmlText = MoneyUtil.getGoldHtml(Cache.instance.role.money.goldBind);
            return;
        }

        public updateExplorerRecords(): void
        {
            var loc1=null;
            if (this._overviewPanel) 
            {
                loc1 = ExplorerRumorData.getNoticeArray(GameConst.DramaLotteryExplorerType);
                if (loc1 == null) 
                {
                    loc1 = [];
                }
                this._overviewPanel.update(loc1);
            }
            return;
        }

        /* internal */ /* var */_spLeft: FlowerBg;

        /* internal */ /* var */_showList: TilePanel;

        /* internal */ /* var */_refreshBtn: GButton;

        /* internal */ /* var */_costTips: Object /* flash.text.TextField */;

        /* internal */ /* var */_ybTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_ybBindTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_useBindYbCB: GCheckBox;

        /* internal */ /* var */_leftFreeTimes: int;

        /* internal */ /* var */_itemArr: Array<any>;

        /* internal */ /* var */_itemObject: Object;

        /* internal */ /* var */_profilePanel: DramaLotteryProfilePanel;

        /* internal */ /* var */_overviewPanel: DramaLotteryOverviewPanel;
    }
